home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / dev / misc / icqsocket.lha / isdev / logview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  5.7 KB  |  282 lines

  1. /*
  2.  
  3.  LogView.c
  4.  
  5.  Shows messages in the ICQSocket message log.
  6.  
  7.  Usage (from shell): LogView <UIN>
  8.  
  9. */
  10.  
  11.  
  12. #include <libraries/mui.h>
  13. #include <libraries/gadtools.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #include <mui/busy_mcc.h>
  19. #include <MUI/NListview_mcc.h>
  20. #include <MUI/NFloattext_mcc.h>
  21. #include <proto/muimaster.h>
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. #include "icqsocket.h"
  28. #include "icqsocket_pragmas.h"
  29.  
  30. struct Library *MUIMasterBase;
  31. struct ICQSocketBase *ICQSocketBase;
  32.  
  33. ICQHandle *ih;
  34.  
  35. APTR window, dl_close, dl_fwd, dl_list, dl_del, dl_reply;
  36. APTR app;
  37.  
  38. __asm __saveds ULONG dl_dispfunc(register __a2 char **array, register __a1 ICQMessage *item)
  39. {
  40.     static char tpbfr[32];
  41.     static char uinbfr[32];
  42.     static char txt[32];
  43.     static char date[32];
  44.     static char time[32];
  45.     char *sent;
  46.  
  47.     if(item) {
  48.  
  49.         if(item->Instant=55) {
  50.             /* This message is _sent_ by item->UIN */
  51.             array[3]="Sent to";
  52.         } else {
  53.             array[3]="Recieved from";
  54.         }
  55.  
  56.         switch(item->Type) {
  57.             case MST_TEXT:
  58.                 array[0]="Text";
  59.                 break;
  60.             case MST_URL:
  61.                 array[0]="URL";
  62.                 break;
  63.             case MST_AUTHORIZE:
  64.                 array[0]="Authorize";
  65.                 break;
  66.             case MST_REQAUTH:
  67.                 array[0]="Auth. request";
  68.                 break;
  69.             case MST_USERADDED:
  70.                 array[0]="User added";
  71.                 break;
  72.             case MST_CONTACTS:
  73.                 array[0]="Contacts";
  74.                 break;
  75.             default:
  76.                 sprintf(tpbfr, "Unknown: %ld", item->Type);
  77.                 array[0]=tpbfr;
  78.         }
  79.  
  80.         sprintf(date, "%ld-%02ld-%02ld", item->Time.Year, item->Time.Month, item->Time.Day);
  81.         sprintf(time, "%02ld:%02ld", item->Time.Hour, item->Time.Minute);
  82.  
  83.         array[1]=date;
  84.         array[2]=time;
  85.  
  86.         //if(item->le_Status=='S') {
  87.         //    sprintf(uinbfr, "\0331%ld", item->UIN);
  88.         //} else {
  89.             sprintf(uinbfr, "\0332%ld", item->UIN);
  90.         //}
  91.  
  92.         array[4]=uinbfr;
  93.  
  94.         strncpy(txt, item->Msg, 30);
  95.  
  96.         txt[28]='.';
  97.         txt[29]='.';
  98.         txt[30]='.';
  99.         txt[31]='\0';
  100.  
  101.         array[5]=txt;
  102.         
  103.         //printf("Displaying %s\n", txt);
  104.     } else {
  105.         array[0]="Type";
  106.         array[1]="Date";
  107.         array[2]="Time";
  108.         array[3]="Direction";
  109.         array[4]="User";
  110.         array[5]="Message";
  111.     }
  112.  
  113.     return (ULONG)0;
  114. }
  115.  
  116. struct Hook dl_disphook = { {NULL, NULL}, (void *)dl_dispfunc, NULL, NULL };
  117.  
  118. __asm __saveds ULONG dl_consfunc(register __a2 APTR pool, register __a1 ICQMessage *item)
  119. {
  120.     APTR z;
  121.  
  122.     //printf("item->Size: %ld\n", item->Size);
  123.  
  124.     z=AllocPooled(pool, item->Size);
  125.     if(z) {
  126.         CopyMem(item, z, item->Size);
  127.     }
  128.  
  129.     return (ULONG)z;
  130. }
  131.  
  132. struct Hook dl_conshook = { {NULL, NULL}, (void *)dl_consfunc, NULL, NULL };
  133.  
  134. __asm __saveds ULONG dl_desfunc(register __a2 APTR pool, register __a1 ICQMessage *item)
  135. {
  136.     FreePooled(pool, item, item->Size);
  137.     return (ULONG)0;
  138. }
  139.  
  140. struct Hook dl_deshook = { {NULL, NULL}, (void *)dl_desfunc, NULL, NULL };
  141.  
  142. void ShutdownMUI(APTR app, char *str)
  143. {
  144.     if(app)    MUI_DisposeObject(app);
  145.  
  146.     if(MUIMasterBase) CloseLibrary(MUIMasterBase);
  147.     
  148.     if(str) {
  149.         puts(str);
  150.         exit(20);
  151.     }
  152.     exit(0);
  153. }
  154.  
  155. void InitMUI(void)
  156. {
  157.     if(!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  158.         ShutdownMUI(NULL,"Could not open "MUIMASTER_NAME".");
  159. }
  160.  
  161. BOOL HandleInput(ULONG x)
  162. {
  163.     switch(x)
  164.     {
  165.         case MUIV_Application_ReturnID_Quit:
  166.         //case MEN_QUIT:
  167.             return TRUE;
  168.             break;
  169.  
  170.     }
  171.     return FALSE;
  172. }
  173.  
  174. APTR CreateApp(STRPTR title)
  175. {
  176.     ICQMessage *im;
  177.     APTR app;
  178.  
  179.     app=ApplicationObject,
  180.             MUIA_Application_Title      , "ICQSocket Message Log",
  181.             MUIA_Application_Version    , "$VER:  ICQLog 1.1 (15.10.99)",
  182.             MUIA_Application_Copyright  , "©1999 Henrik Isaksson",
  183.             MUIA_Application_Author     , "Henrik Isaksson",
  184.             MUIA_Application_Description, "Message log viewer for ICQSocket.",
  185.             MUIA_Application_Base       , "ICQLOG",
  186.  
  187.             SubWindow, window = WindowObject,
  188.                 MUIA_Window_Title, title,
  189.                 MUIA_Window_ID,        0x00000001,
  190.  
  191.                 WindowContents, VGroup,
  192.                     Child, dl_list=NListviewObject,
  193.                             MUIA_NListview_NList, NListObject,
  194.                                 MUIA_NList_DisplayHook, &dl_disphook,
  195.                                 MUIA_NList_DestructHook, &dl_deshook,
  196.                                 MUIA_NList_ConstructHook, &dl_conshook,
  197.                                 MUIA_NList_EntryValueDependent, TRUE,
  198.                                 MUIA_NList_Format, "BAR,BAR,BAR,BAR,BAR,BAR",
  199.                                 MUIA_NList_TitleSeparator, TRUE,
  200.                                 MUIA_NList_Title,    TRUE,
  201.                             End,
  202.                         End,
  203.                     Child, RectangleObject,
  204.                         MUIA_Rectangle_HBar,    TRUE,
  205.                         MUIA_FixHeight,        8,
  206.                         End,
  207.                     Child, HGroup,
  208.                         /*Child, dl_fwd=SimpleButton("Forward"),
  209.                         Child, HSpace(0),
  210.                         Child, dl_reply=SimpleButton("Reply"),
  211.                         Child, HSpace(0),
  212.                         Child, dl_del=SimpleButton("Delete"),*/
  213.  
  214.                         Child, HSpace(0),
  215.                         Child, dl_close=SimpleButton("Close"),
  216.                         Child, HSpace(0),
  217.                         End,
  218.                     End,
  219.                 End,
  220.         
  221.             End;
  222.     if(app) {
  223.         DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  224.             app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  225.         set(window, MUIA_Window_Open, TRUE);
  226.  
  227.  
  228.         //printf("Opening msg log..\n");
  229.  
  230.         if(is_OpenMsgLog(ih)) {
  231.             do {
  232.                 //printf("Getting logged message..\n");
  233.                 im=is_GetLoggedMsg(ih, 0);
  234.                 if(im) {
  235.                     //printf("msg: %s\n", im->Msg);
  236.                     DoMethod(dl_list, MUIM_NList_InsertSingle, im, MUIV_NList_Insert_Bottom);
  237.                 }
  238.             } while(im);
  239.             is_CloseMsgLog(ih);
  240.         }
  241.     }
  242.     
  243.     return app;
  244. }
  245.  
  246. void main(int argc, char *argv[])
  247. {
  248.     APTR app;
  249.     ULONG signals, inp, uin;
  250.     BOOL Quit=FALSE;
  251.  
  252.     if(argc<2) {
  253.         printf("USAGE: LogView UIN\n");
  254.         exit(0);
  255.     }
  256.  
  257.     uin=atoi(argv[1]);
  258.  
  259.     InitMUI();
  260.  
  261.     //printf("MUI initialised!\n");
  262.  
  263.     ICQSocketBase=(struct ICQSocketBase *)OpenLibrary("icqsocket.library", 1);
  264.     if(ICQSocketBase) {
  265.         if((ih=is_InitA(uin, NULL))) {
  266.             //printf("ICQSocket initialised\n");
  267.             app=CreateApp(argv[1]);
  268.             if(app) {
  269.                 while(!Quit) {
  270.                     inp=DoMethod(app,MUIM_Application_Input,&signals);
  271.                     Quit=HandleInput(inp);
  272.                     if(signals) Wait(signals);
  273.                 }
  274.                 is_Free(ih);
  275.             }
  276.         }
  277.         CloseLibrary((struct Library *)ICQSocketBase);
  278.     }
  279.  
  280.     ShutdownMUI(app, NULL);
  281. }
  282.